package com.itheima.d3_resource;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 目标：掌握释放资源的方式:try-catch-finally
 */
public class Test1 {
    public static void main(String[] args) throws IOException {

        File src = new File("day09file-io-app/image01/R-C.jpg");

        File file = new File("day09file-io-app/image02/R-C.jpg");

        copyFile(src,file);
    }
    public static void copyFile(File src,File file)  {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
             fis = new FileInputStream(src);
             fos = new FileOutputStream(file);

            byte[] buf = new byte[1024];
            int len;
            while ((len= fis.read(buf))!=-1){
                fos.write(buf,0,len);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

